package com.chixing.day10.ExpectionsDemo;

import java.io.IOException;

public class BankDEMO {
    private int accNo;   //账户账号
    private String accName;  //账户姓名
    private String accPassword;  //账户密码
    private long accTelno;  //账户手机号
    private float accBalance; //账户余额
    private int accType; //账户类型 0:储蓄账户, 1：信用账户

    public BankDEMO() {
    }

    public BankDEMO(int accNo, String accName, String accPassword, long accTelno, float accBalance, int accType) {
        this.accNo = accNo;
        this.accName = accName;
        this.accPassword = accPassword;
        this.accTelno = accTelno;
        this.accBalance = accBalance;
        this.accType = accType;
    }

    public int getAccNo() {
        return accNo;
    }

    public void setAccNo(int accNo) {
        this.accNo = accNo;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public String getAccPassword() {
        return accPassword;
    }

    public void setAccPassword(String accPassword) {
        this.accPassword = accPassword;
    }

    public long getAccTelno() {
        return accTelno;
    }

    public void setAccTelno(long accTelno) {
        this.accTelno = accTelno;
    }

    public float getAccBalance() {
        return accBalance;
    }

    public void setAccBalance(float accBalance) {
        this.accBalance = accBalance;
    }

    public int getAccType() {
        return accType;
    }

    public void setAccType(int accType) {
        this.accType = accType;
    }

    //账户存款
    public void depoist(float money) {
        this.accBalance += money;
        System.out.println("存款成功！余额为:" + this.accBalance);
    }

    //账户取款:调用余额不足异常
    public void withdraw(float money) throws BalancdNotEnoughException{
        if(this.accBalance < money){
            throw new BalancdNotEnoughException();
        }else {
            this.accBalance -= money;
            System.out.println("取款成功！余额为:" + this.accBalance);
        }
    }

    //转账
    public void transfer(float money,BankDEMO bank) throws BalancdNotEnoughException{
        if(this.accBalance < money){
            throw new BalancdNotEnoughException("转账时您的余额不足,请充值！！");
        }else{
            this.accBalance -= money;
            bank.accBalance += money;
            System.out.println("转账成功");
        }

    }


}
